package com.zhongketech.sunflower.utils;

import java.io.DataOutputStream;
import java.util.List;

import com.zhongketech.sunflower.transport.LogUtil;


public class Root {

	private static final String TAG = "CheckRoot";


	public static void doCmds(List<String> cmds) throws Exception {
		Process process = Runtime.getRuntime().exec("su");
		DataOutputStream os = new DataOutputStream(process.getOutputStream());
		for (String tmpCmd : cmds) 
		{
			os.writeBytes(tmpCmd+"\n");
		}
		os.writeBytes("exit\n");
		os.flush();
		os.close();
		process.waitFor();
	} 


	public static boolean preparesu() {
		Process process = null;
		DataOutputStream os = null;
		try {
			String cmd="chmod 777 " + "/system/build.prop";
			process = Runtime.getRuntime().exec("su"); //切换到root帐号
			os = new DataOutputStream(process.getOutputStream());
			os.writeBytes(cmd + "\n");
			os.writeBytes("exit\n");
			os.flush();
			process.waitFor();
		} catch (Exception e) {
			return false;
		} finally {
			try {
				if (os != null) {
					os.close();
				}
				process.destroy();
			} catch (Exception e) {
			}
		}

		LogUtil.i(TAG,"get root succ");
		return true;
	}
}